//
//  WQStatusRetweetedCell.swift
//  sanwuWeibo
//
//  Created by 王先强 on 15/12/13.
//  Copyright © 2015年 王先强. All rights reserved.
//

import UIKit

class WQStatusRetweetedCell: WQHomeCell {

    //微博视图模型
    //如果继承父类的属性
    //1.需要override
    //2.不需要调super
    //3.先执行父类的didSet，在执行子类的didSet -> 只关心子类的设置就OK
    //
    override var statusViewModel: WQStatusViewModel? {
        didSet{
            
            retweetedLabel.text = statusViewModel?.retweetedStatusContent
            
            pictureView.snp_updateConstraints { (make) -> Void in
                make.width.equalTo(pictureView.bounds.width)
                make.height.equalTo(pictureView.bounds.height)
                
                let offSet = (statusViewModel?.thumbnailUrls.count > 0) ? homeCellSubViewsMargin : 0
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offSet)
                
            }
        }
    }
 

    
    
    //懒加载转发微博的另外两个控件
    //背景按钮
    private lazy var bgButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        return btn
    }()
    //转发微博内容的lable
    private lazy var retweetedLabel: UILabel = {
    
        let lbl = UILabel(title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博", color: UIColor.darkGrayColor(), fontSize: 13)
        lbl.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * homeCellSubViewsMargin
        lbl.textAlignment = .Left
        return lbl
    }()
    
  
}

extension WQStatusRetweetedCell {
    override func setupUI() {
        super.setupUI()
        
        contentView.insertSubview(bgButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: bgButton)
        
        bgButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(homeCellSubViewsMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(statusTabbar.snp_top)
            
        }
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(bgButton.snp_top)
            make.left.equalTo(bgButton.snp_left).offset(homeCellSubViewsMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom)
            make.left.equalTo(retweetedLabel.snp_left)
//            make.width.equalTo(300)
//            make.height.equalTo(120)
        }
        
    }

}

